define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'team/index' + location.search,
                    // add_url: 'team/add',
                    edit_url: 'team/edit',
                    //del_url: 'team/del',
                    multi_url: 'team/multi',
                    // import_url: 'team/import',
                    table: 'team',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 't_id',
                sortName: 't_id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'delete', title: __('Delete'), searchList: {"0":__('Delete 0'),"1":__('Delete 1')}, formatter: Table.api.formatter.toggle},
                        {field: 'captain', title: __('Captain'),visible:false},
                        {field: 'user.username', title: __('User.username'), operate: 'LIKE'},
                        {field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE'},
                        {field: 'is_store', title: __('Is_store'), searchList: {"0":__('Is_store 0'),"1":__('Is_store 1')}, formatter: Table.api.formatter.normal},
                        {field: 'store_id', title: __('Store_id')},
                        {field: 'store.store_name', title: __('Store.store_name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'title', title: __('Title'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'start_date', title: __('Start_date')},
                        {field: 'end_date', title: __('End_date')},
                        {field: 'number_people', title: __('Number_people')},
                        {field: 'join_number', title: __('Join_number')},
                        {field: 'ordered_number', title: __('Ordered_number')},
                        {field: 'cost', title: __('Cost'), operate:'BETWEEN'},
                        {field: 'level', title: __('Level')},
                        {field: 'address', title: __('Address'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'long', title: __('Long'), operate:'BETWEEN'},
                        {field: 'lat', title: __('Lat'), operate:'BETWEEN'},
                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1')}, formatter: Table.api.formatter.status},
                        {field: 'release', title: __('Release'), searchList: {"0":__('Release 0'),"1":__('Release 1'),"2":__('Release 2')}, formatter: Table.api.formatter.normal},
                        {field: 'is_system', title: __('Is_system'), searchList: {"0":__('Is_system 0'),"1":__('Is_system 1')}, formatter: Table.api.formatter.normal},
                        {field: 'pay_status', title: __('Pay_status'), searchList: {"0":__('Pay_status 0'),"1":__('Pay_status 1')}, formatter: Table.api.formatter.status},
                        {field: 'confirm', title: __('Confirm'), searchList: {"0":__('Confirm 0'),"1":__('Confirm 1')}, formatter: Table.api.formatter.normal},
                        {field: 'ct_date', title: __('Ct_date')},
                        {field: 'up_date', title: __('Up_date')},

                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,buttons: [
                            {
                                name: '删除',
                                text: '删除',
                                title: '删除',
                                classname: 'btn btn-xs btn-success btn-ajax btn-del',
                                url: 'team/del',
                                confirm: '确认删除？',
                                refresh: true,
                                visible: function(row){
                                    if(row.delete == 1){
                                        return true;
                                    }else{
                                        return false;
                                    }
                                }
                            },
                            ] }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
